/**
 * Copyright 2006 Brad Reynolds
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.leeloo.core;

import junit.framework.TestCase;

public class TagTest extends TestCase {
    public void testConstructorParameters() throws Exception {
        try {
            new Tag(null, "value"); //$NON-NLS-1$ 
            fail("exception should have been thrown"); //$NON-NLS-1$
        } catch (IllegalArgumentException e) {
        }
    }
    
    public void testGetDisplay() throws Exception {
        String name = "name"; //$NON-NLS-1$
        String value = "value"; //$NON-NLS-1$
        Tag tag = new Tag(name, value);
        String display = tag.getDisplay();
        
        assertNotNull(display);
        assertEquals(name + Tag.DISPLAY_SEPARATOR + value, display); 
    }
    
    public void testEqualsAndHashCode() throws Exception {
        Tag tag1 = new Tag("name", "value"); //$NON-NLS-1$ //$NON-NLS-2$
        Tag tag2 = new Tag("name", "value");   //$NON-NLS-1$//$NON-NLS-2$
        
        assertEquals(tag1, tag2);
        assertEquals(tag1.hashCode(), tag2.hashCode());
    }
    
    public void testFromDisplay() throws Exception {
        String name = "name"; //$NON-NLS-1$
        String value = "value"; //$NON-NLS-1$
        
        Tag tag = Tag.fromDisplay(name + Tag.DISPLAY_SEPARATOR + value);
        assertNotNull(tag);
        assertEquals(name, tag.getName());
        assertEquals(value, tag.getValue());
    }
    
    public void testFromStringInvalidDisplay() throws Exception {
        try {
            Tag.fromDisplay("namevalue"); //$NON-NLS-1$
            fail("exception should have been thrown"); //$NON-NLS-1$
        } catch (IllegalArgumentException e) {
        }
    }
    
    public void testCompareTo() throws Exception {
        Tag a = new Tag("a", ""); //$NON-NLS-1$ //$NON-NLS-2$
        Tag b = new Tag("b", "");  //$NON-NLS-1$//$NON-NLS-2$
        assertTrue(a.compareTo(b) < 0);
        assertTrue(b.compareTo(a) > 0);
        assertTrue(a.compareTo(new Tag("a", "")) == 0); //$NON-NLS-1$ //$NON-NLS-2$
    }
}